package easy;

public class a821_字符的最短距离 {
    public int[] shortestToChar(String s, char c) {
        int[] ans = new int[s.length()];
        int[] message = new int[s.length()];
        int i = 0;
        for (int j = 0; j < s.length(); j++) {
            if (s.charAt(j) == c) {
                message[i] = j;
                ++i;
            }
        }
        for (int j = 0; j < s.length(); j++) {
            int temp = Integer.MAX_VALUE;
            for (int k = 0; k < i; k++) {

                temp = Math.min(Math.abs(message[k] - j), temp);
            }
            ans[j] = temp;
        }

        return ans;
    }
}
